#include "StdAfx.h"
#include "BlastPileManager.h"

CBlastPileManager::CBlastPileManager(CdmDB* pBoundaryDB, CDataTable* pBlastHoleTable, CdmDB* pDisplayDB)
	: m_pBoundaryDB(pBoundaryDB)
	, m_pBlastHoleTable(pBlastHoleTable)
	, m_pDisplayDB(pDisplayDB)
	, m_pConfigurator(NULL)
	, m_pMesher(NULL)
	, m_pEstimator(NULL)
	, m_pOpimizer(NULL)
{
	m_pConfigurator = new CBlastPileConfigurator(m_pBoundaryDB, m_pBlastHoleTable, m_pDisplayDB);
}

CBlastPileManager::~CBlastPileManager(void)
{
	if (m_pConfigurator != NULL)
	{
		delete m_pConfigurator;
		m_pConfigurator = NULL;
	}

	if (m_pMesher != NULL)
	{
		delete m_pMesher;
		m_pMesher = NULL;
	}

	if (m_pEstimator != NULL)
	{
		delete m_pEstimator;
		m_pEstimator = NULL;
	}

	if (m_pOpimizer != NULL)
	{
		delete m_pOpimizer; 
		m_pOpimizer = NULL;
	}
}

bool CBlastPileManager::CreateMesher(CBlastPile2010* pBlastPile/* = NULL*/)
{
	if (NULL == m_pConfigurator)
		return false;

	if (NULL == m_pMesher)
	{
		m_pMesher = new CBlastPileMesher(pBlastPile);
	}
	else
	{
		m_pMesher->SetBlastPile(pBlastPile);
	}

	return true;
}

bool CBlastPileManager::CreateEstimator()
{
	if (NULL == m_pConfigurator || NULL == m_pMesher)
		return false;

	if (NULL == m_pEstimator)
	{
		m_pEstimator = new CBlastPileEstimator;
	}

	return true;
}

bool CBlastPileManager::CreateOptimizer()
{
	if (NULL == m_pConfigurator || NULL == m_pMesher || NULL == m_pMesher)
		return false;

	if (NULL == m_pOpimizer)
	{
		m_pOpimizer = new CBlastPileOptimizer;
	}

	return true;
}
